<?php
include_once(dirname(__FILE__).'/../lib/Log.class.php');
include_once(dirname(__FILE__).'/../lib/Db.class.php');
abstract class MarketTree{
    protected $log;
    private $db;
    private $pid;

    function __construct($pid)
    {
        $this->db = Db::getInstance();
        $this->pid = $pid;
    }
    public final function create()
    {
        $makeJson = function($query_result){
            $info = array();
            if(is_array($query_result))
            {
                foreach($query_result as $row)
                {
                    array_push($info,$this->getTreeSubItem($row));
                }
            }
             return json_encode($info);
         };
         $json_data = $this->db->db_query($this->getSql(),$makeJson);
         return $json_data;
    }
    abstract protected function getSql();
    abstract protected function getTreeSubItem($row);
    protected function getPid()
    {
        return $this->pid;
    }
}
?>
